package com.bc004346.travelus.model.domain;

import java.io.Serializable;

/**
 * Created by Renats on 11/10/2014.
 * Handles Origin - Destination round trip
 */
public class DayTrip implements Serializable {

    private Flight mOutboundFlight;
    private Flight mInboundFlight;

    public DayTrip(Flight outbound, Flight inbound){
        setOutboundFlight(outbound);
        setInboundFlight(inbound);
    }

    public Flight getInboundFlight() {
        return mInboundFlight;
    }

    public void setInboundFlight(Flight flight) {
        this.mInboundFlight = flight;
    }

    public Flight getOutboundFlight() {
        return mOutboundFlight;
    }

    public void setOutboundFlight(Flight flight) {
        this.mOutboundFlight = flight;
    }

    public String getTripDuration() {

        long diffInSeconds = (mInboundFlight.getArrival().getTime() - mOutboundFlight.getDeparture().getTime()) / 1000;

        long diff[] = new long[]{0, 0};
        diff[1] = (diffInSeconds = (diffInSeconds / 60)) >= 60 ? diffInSeconds % 60 : diffInSeconds;
        diff[0] = (diffInSeconds = (diffInSeconds / 60)) >= 24 ? diffInSeconds % 24 : diffInSeconds;

        return String.format(
                "%dh, %dm",
                diff[0],
                diff[1]);
    }

    public String getBootOnTheGroundDuration() {

        long diffInSeconds = (mInboundFlight.getDeparture().getTime() - mOutboundFlight.getArrival().getTime()) / 1000;

        long diff[] = new long[]{0, 0};
        diff[1] = (diffInSeconds = (diffInSeconds / 60)) >= 60 ? diffInSeconds % 60 : diffInSeconds;
        diff[0] = (diffInSeconds = (diffInSeconds / 60)) >= 24 ? diffInSeconds % 24 : diffInSeconds;

        return String.format(
                "%dh, %dm",
                diff[0],
                diff[1]);
    }

    @Override
    public String toString() {
        return "Outbound: " + mOutboundFlight
                + "; Inbound: " + mInboundFlight
                + "; trip duration: " + getTripDuration()
                + "; boot on the ground: " + getBootOnTheGroundDuration();
    }
}
